var map;
var markersArray = [];
var icone;
var gmv=-1;

  function initialize() {
    var latlng = new google.maps.LatLng(16.594081, 9.31640625);
    var myOptions = {
      zoom: 4,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.HYBRID
    };
    icone = new google.maps.MarkerImage('../elements/greencirclemarker.png');
    map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
  }
  
  function addMarker(location) {
	  marker = new google.maps.Marker({
	    position: location,
	    //icon: icone,
	    map: map
	  });
	  markersArray.push(marker);
	}
  function clearOverlays() {
	  if (markersArray) {
	    for (i in markersArray) {
	      markersArray[i].setMap(null);
	    }
	  }
	}

	// Shows any overlays currently in the array
	function showOverlays() {
	  if (markersArray) {
	    for (i in markersArray) {
	      markersArray[i].setMap(map);
	    }
	  }
	}

	// Deletes all markers in the array by removing references to them
	function deleteOverlays() {
	  if (markersArray) {
	    for (i in markersArray) {
	      markersArray[i].setMap(null);
	    }
	    markersArray.length = 0;
	  }
	}
	
	/*google.maps.LatLng.prototype.distanceFrom = function(newLatLng) {
	    var lat1 = this.lat() * Math.PI / 180.0;
	    var lat2 = newLatLng.lat() * Math.PI / 180.0;
	    var lngDiff = (newLatLng.lng() - this.lng()) * Math.PI / 180.0;
	    var a = Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1)
	* Math.cos(lat2) * Math.cos(lngDiff)) * 20902231.0029; ;
	    return Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1)
	* Math.cos(lat2) * Math.cos(lngDiff)) * 20902231.0029;
	}*/
	
	google.maps.LatLng.prototype.distanceFrom = function(newLatLng) {
		//var R = 6371; // km (change this constant to get miles)
		var R = 6371000; // meters
		var lat1 = this.lat();
		var lon1 = this.lng();
		var lat2 = newLatLng.lat();
		var lon2 = newLatLng.lng();
		var dLat = (lat2-lat1) * Math.PI / 180;
		var dLon = (lon2-lon1) * Math.PI / 180;
		var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
		  Math.cos(lat1 * Math.PI / 180 ) * Math.cos(lat2 * Math.PI / 180 ) *
		  Math.sin(dLon/2) * Math.sin(dLon/2);
		var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
		var d = R * c;
		return d;
	};

	/*google.maps.Map.prototype.fromLatLngToDivPixel = function(a){
	    if(!this.helperOverlay) return {x:0,y:0};
	    return this.helperOverlay.getProjection().fromLatLngToDivPixel(a);
	}*/